package com.defang.award;

import com.defangit.award.domain.Award;
import com.defangit.award.orm.AwardService;
import laogen.lang.exception.ParameterNotValidException;

import javax.ws.rs.*;
import java.util.List;

/**
 * Created by zhangfagen on 2019/1/2.
 */
@Path("award")
public class AwardResource {
    @GET @Produces("application/json")
    public List<Award> all(){
        return new AwardService().all();
    }

    @POST
    public boolean addAward(Award award){
        return new AwardService().addAward(award)!=null;
    }


    @GET @Path("{id}") @Produces("application/json")
    public Award award(@PathParam("id") int id){
        return new AwardService().get(id).orElseThrow(
                ()-> ParameterNotValidException.zeroIdOrEntityNonExist("抽奖id")
        );
    }

    @DELETE @Path("{id}")
    public boolean delAward(@PathParam("id")int id){
        return new AwardService().delAward(id);
    }
}
